* http://www.nber.org/morg/annual/
clear all
set more off
global folder /Users/yasenov/Dropbox/mariel_boatlift/revision_version/revision_data/
cd "/Users/yasenov/Desktop/research/replication_papers/Card_Mariel_Boatlift/cps morg raw"
use "morg86.dta"
append using "morg87.dta"
append using "morg88.dta"
append using "morg89.dta"
append using "morg90.dta"
append using "morg91.dta"
append using "morg92.dta"
append using "morg93.dta"
append using "morg94.dta"
append using "morg95.dta"
append using "morg96.dta"
append using "morg97.dta"
append using "morg98.dta"
append using "morg98.dta"
append using "morg99.dta"
append using "morg00.dta"
append using "morg01.dta"
append using "morg02.dta"

merge m:1 cmsarank pmsarank using $folder/crosswalk.dta, nogenerate update 

keep if age >= 16 & age <= 61
keep if msafips != .
drop if weight <= 0 | weight == .

***************************
/* DEMOGRAPHIC VARIABLES */
***************************
gen low_skilled = 0
replace low_skilled = 1 if gradeat < 12
replace low_skilled = 1 if gradeat == 12 & gradecp == 2
replace low_skilled = 1 if grade92 <= 38
gen college = gradeat >= 16
replace college = 0 if gradeat == 16 & gradecp == 2

gen male = sex == 1
gen white = (race == 1 & ethnic == 8)
gen black = (race == 2 & ethnic == 8)
gen hisp = (ethnic != 8 & ethnic != 5)
gen cuban = (ethnic == 5)
gen young = age < 30
gen hisp_lowskilled = (ethnic != 8 & low_skilled == 1)
gen cuban_lowskilled = (cuban == 1 & low_skilled == 1)

gen manuf = .
replace manuf = 1 if ind80 >= 100 & ind80 < 400
replace manuf = 0 if manuf == . & ind80 != 0

****************************
/* LABOR MARKET VARIABLES */
****************************
gen uearnhre = (earnwke/uhourse)
drop earnhr* uhourse 

global vars uearnhre earnwke
foreach i of global vars {
	replace `i' = `i' * 1.3775 if year == 1985 
	replace `i' = `i' * 1.3513 if year == 1986 
	replace `i' = `i' * 1.3046 if year == 1987 
	replace `i' = `i' * 1.2532 if year == 1988
	replace `i' = `i' * 1.1959 if year == 1989
	replace `i' = `i' * 1.1344 if year == 1990 
	replace `i' = `i' * 1.0886 if year == 1991
	replace `i' = `i' * 1.0564 if year == 1992
	replace `i' = `i' * 1.0259 if year == 1993 
	replace `i' = `i' * 1 if year == 1994 
	replace `i' = `i' * 0.9727 if year == 1995 
	replace `i' = `i' * 0.9449 if year == 1996
	replace `i' = `i' * 0.9234 if year == 1997
	replace `i' = `i' * 0.9093 if year == 1998 
	replace `i' = `i' * 0.8898 if year == 1999
	replace `i' = `i' * 0.8608 if year == 2000
	replace `i' = `i' * 0.8372 if year == 2001
	replace `i' = `i' * 0.8241 if year == 2002
	replace `i' = `i' * 0.8056 if year == 2003
	replace `i' = `i' * 0.7846 if year == 2004
	gen log`i' = log(`i') 
}

gen unemp = . 
replace unemp = 1 if ftpt79 == 3 | ftpt89 == 6 | ftpt94 == 11
replace unemp = 0.5 if ftpt79 == 5 | ftpt89 == 7 | ftpt94 == 12
replace unemp = 0 if ftpt79 == 1 | ftpt79 == 2 | ftpt79 == 4 
replace unemp = 0 if (ftpt89 >=2 & ftpt89 <=5)
replace unemp = 0 if ftpt94 == 2 | ftpt94 == 3 
replace unemp = 0 if (ftpt94 >= 6  & ftpt94 <= 9)

saveold $folder/aux_nonevent.dta, replace

****************
/* COLLAPSING */
****************
* C O N T R O L S - DEMOGRAPHICS
preserve
global vars low_skilled college male age white black hisp cuban young agri manuf  ///
	hisp_lowskilled cuban_lowskilled
collapse (mean) $vars [pw=weight], by(year msafips)
saveold $folder/msa_controls_nonevent.dta", replace
restore
